<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 统计数组中元素出现的次数 
    [1,2,3,1,1,1,2,2,3,3,4]
    1出现的次数 4
    2出现的次数 3
    3出现的次数 3
    4出现的次数 1
    -->
    <script>
        var arr= [1,2,3,1,1,1,2,2,3,3,4]
        
        var res=arr.reduce(function(pre,cur){
            if(cur in pre){
                pre[cur]+=1
            }else{
                pre[cur]=1
            }
            return pre
        },{})
        for(var key in res){
            console.log(key+'出现的次数'+res[key]);
            
        }
    </script>
</body>

</html>